<?php
 Zend_Loader::loadClass("CodesUtility");
 Zend_Loader::loadClass("BaseDBRow");
 class Address extends BaseDBRow
 {
	const _tablename = "projecte_entity.addresses";
 	protected function setUp()
 	{
 		$this->_tableName = self::_tablename;		
 	}
	
	public function getAddressById($addressId) {
	
		Zend_Loader::loadClass("QueryCreator");
		Zend_Loader::loadClass("Country");
		
		$query = new QueryCreator();
		$query->addSelect("concat(address1, if(address2 <> '', concat(', ', address2),''), if(city <> '',concat(', ',city),''), if(province <> '',concat(', ',province),''), if(a.country_code <> '',concat(', ',c.country,' ', zip),'')) address");
		$query->addFrom($this->_tableName . " a ");
		$query->addJoin(" left join " . Country::_tablename . " c on a.country_code = c.country_code ");
		$query->addWhere(" a.address_id = " . $addressId);
		
		$db = DBCon::instance();
		// echo  $query->createSQL();die();
		$result = $db->executeQuery($query->createSQL());
		return $result;
		
	}
	
	
 }
?>